package com.ruoyi.test.controller;

import com.ruoyi.test.domain.Person;
import com.ruoyi.test.domain.Student;
import com.ruoyi.test.domain.Teacher;

import java.util.ArrayList;
import java.util.List;

/**
 * @projectName: ruoyi
 * @package: com.ruoyi.test.controller
 * @className: study1
 * @author: WBK
 * @description: TODO
 * @date: 2024/11/26 16:13
 * @version: 1.0
 */
public class Study1 {

    public static List<Student> getStudentByName(List<Student> allStudent, String studentName){

//        student1.getName(); // get方法 是取值用的
//        student1.setName("王五"); // set方法 是赋值用的

//        Student se = allStudent.get(0);
//        Teacher te

        // 从allStudent中筛选出名字为"张三"的学生 放到newStudentList中
        List<Student> newStudentList = new ArrayList<>();

        for(int i=0; i<allStudent.size(); i++)
        {
            Student s = allStudent.get(i);
            if(s.getName().equals(studentName))
            {
                newStudentList.add(s);
            }

        }

        return newStudentList;
    }


    public static List<Student> getStudentByName1(List<Student> allStudent, String studentName){

        // 从allStudent中筛选出名字为"张三"的学生 放到newStudentList中
        List<Student> newStudentList = new ArrayList<>();

        for(int i=0;i< allStudent.size();i++)
        {
            Student se = allStudent.get(i);
            if(se.getName().equals(studentName))
            {
                newStudentList.add(se);
            }

        }


        return newStudentList;
    }

    public static void main(String[] args) {

        // 创建两个学生对象
        Student student1 = new Student(1, "张三", "男", 18);
        Student student2 = new Student(2, "李四", "女", 19);

        List<Student> allStudent = new ArrayList<>();

        allStudent.add(student1);
        allStudent.add(student2);


        // test

        // getStudentByName
        List<Student> studentList1 = getStudentByName1(allStudent, "张三");

        System.out.println(studentList1);
        System.out.println("--------------");

        List<Student> studentList2 = getStudentByName1(allStudent, "李四");

        System.out.println(studentList2);

    }

}
